package douyin;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.jsoup.Connection;
import org.jsoup.Connection.Method;
import org.jsoup.Connection.Response;
import org.jsoup.Jsoup;
import org.jsoup.UnsupportedMimeTypeException;
import org.jsoup.nodes.Document;

public class CopyOfDemo3 {
	public static void main(String[] args) throws IOException {
	 

		String url = "https://aweme.snssdk.com/aweme/v1/playwm/?video_id=4ba77a1fff224e2ea7d6eeba979a3914&line=0";
		
		 
		Response response = Jsoup.connect(url).ignoreContentType(true). execute();
		
		System.out.println("1212"+response.url());
		boolean hasHeader = response.hasHeader("Location");
		
		BufferedInputStream bodyStream = response.bodyStream();
		FileUtils.copyInputStreamToFile(bodyStream, new File("c://1212.mp4"));

		Connection connect2 = Jsoup.connect(url);
		try {
			Response execute = connect2.method(Method.GET).execute();
			
			 
			Map<String, String> headersOne = execute.headers();
			System.out.println("所有头文件值：" + headersOne);
		} catch (Exception e) {

			 if (e instanceof org.jsoup.UnsupportedMimeTypeException) {
				  UnsupportedMimeTypeException ex=(UnsupportedMimeTypeException) (e);
				  System.out.println("---"+ex.toString());
			}
			 String  finalurl= e.toString().substring(e.toString().indexOf("URL=")+4)  ;
			 
			 FileUtils.copyURLToFile(new URL(finalurl), new File("c://1.mp4"));
		}

		
		Response execute = connect2.method(Method.GET).execute();
		Map<String, String> headersOne = execute.headers();
		System.out.println("所有头文件值：" + headersOne);
		System.out.println();

	}
}
